package com.itheima.smspringboot.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.smspringboot.entity.SchoolClass;
import com.itheima.smspringboot.entity.SchoolClassString;
import com.itheima.smspringboot.mapper.SchoolClassMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SchoolClassService {

    @Resource
    private  SchoolClassMapper schoolClassMapper;

    public  void deleteBatch(List<SchoolClassString> schoolClassStringList) {
        for (SchoolClassString schoolClassString : schoolClassStringList) {
            schoolClassMapper.deleteById(schoolClassString.getClassId());
        }
    }

    public  void deleteById(Integer classId) {

        schoolClassMapper.deleteById(classId);

    }

    public  void updateById(SchoolClass schoolClass) {
        schoolClassMapper.updateById(schoolClass);
    }

    public List<SchoolClassString> selectAll(SchoolClassString schoolClassString) {
        return schoolClassMapper.selectAll(schoolClassString);
    }



    public PageInfo selectPage(Integer pageNum, Integer pageSize, SchoolClassString schoolClassString) {
        //H=开启分页查询
        PageHelper.startPage(pageNum, pageSize);
        List<SchoolClassString> list = schoolClassMapper.selectAll(schoolClassString);
        return PageInfo.of(list);

    }

    public void add(SchoolClass schoolClass) {

        if(schoolClass.getMonitor() == null){
            schoolClass.setMonitor(20250508);
        }

        if (schoolClass.getClassAdvisor() == null) {
            schoolClass.setClassAdvisor(20250508);
        }



        schoolClassMapper.insert(schoolClass);
    }






}
